package com.m3958.firstgwt.server.service;

import java.util.Properties;

import org.apache.velocity.app.Velocity;

import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.m3958.firstgwt.server.service.SiteConfiger.SiteConfigerKeyName;

@Singleton
public class VelocityService {

	@Inject
	public VelocityService(SiteConfiger siteConfiger){
		Optional<String> st = Optional.<String>of(siteConfiger.getValue(SiteConfigerKeyName.SITE_ROOT));
		Optional<String> log = Optional.<String>of(siteConfiger.getValue(SiteConfigerKeyName.VELOCITY_LOG_FILE));
		
	    Properties p = new Properties();
	    p.setProperty("file.resource.loader.path", st.get());
	    p.setProperty("runtime.log", log.get());
	    Velocity.init( p );
	}
	
	public boolean templateExists(String tplName){
		return Velocity.resourceExists(tplName);
	}
}
